﻿var editor;
$(document).ready(function () {

    KindEditor.ready(function (K) {
        editor = KindEditor.create('#content', {
            resizeType: 2,
            uploadJson: 'Upload' // 相对于当前页面的路径
        });
        var sid = $("#sid").val();
        var svID = $("#svID").val();
        var svContent = $("#svContent").val();
        var svPreview = $("#svPreview").val();
        if (sid != "") {
            editor.html(svContent);
            $("#pre").val(svPreview);
        }
    });
    $.ajax(
        {
            url: "/Home/GetServiceCategories",
            success: function (data) {
                var result = data;
                var str = "<option value=\"{0}\">{1}</option>";
                var dd = "";
                $(result).each(function () {
                    var temp = this;
                    var html = str.replace("{0}", temp.ID).replace("{1}", temp.SName);
                    dd = dd + html;
                });
                $("#categoryID").html(dd);
                if ($("#svID").val() != "") {
                    $("#categoryID").attr("value", $("#svID").val());
                }
            },
            error: function () {
            }
        }
    );
});
function Save() {
    var categoryID = $("#categoryID :checked").val();
    var html;
    var id = $("#sid").val();
    var pre = $("#pre").val();
    if (pre == "" || pre == undefined) {
        alert("简述不能为空");
        return;
    }
    var title = $("#tb_title").val();
    if (title == "" || title == undefined) {
        alert("标题不能为空");
        return;
    }
    $.ajax({
        url: "/Home/AddArticle",
        data: { "title": title, "pre": pre, "Content": editor.html(), "cid": categoryID, "id": id },
        success: function (data) {
            if (data == 1) {
                alert("操作成功！");
            }
        },
        error: function (jqHR) {
            alert(jqHR + "操作失败");
        }

    });
}
